package com.tony.mywork.huju.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	private static final String date_format = "yyyy-MM-dd HH:mm:ss";
	private static ThreadLocal<DateFormat> threadLocalStrDate = new ThreadLocal<DateFormat>();
	private static ThreadLocal<DateFormat> threadLocalStrUnix = new ThreadLocal<DateFormat>();

	private static final String day_format = "yyyy-MM-dd";
	private static ThreadLocal<DateFormat> threadLocalStrDay = new ThreadLocal<DateFormat>();
	
	public static String getYesterDay() {
		DateFormat df = threadLocalStrDay.get();

		if (df == null) {
			df = new SimpleDateFormat(day_format);
			threadLocalStrDay.set(df);
		}

		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, -1);
		
		return df.format(calendar.getTime());
	}
	
	public static String getDay() {
		DateFormat df = threadLocalStrDay.get();

		if (df == null) {
			df = new SimpleDateFormat(day_format);
			threadLocalStrDay.set(df);
		}

		return df.format(new Date());
	}

	
	public static void main(String[] args) {
		System.out.println(getDay());
		System.out.println(getYesterDay());
	}
	
}
